﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Logistics_Service.DTO;
using System.Data;

namespace Logistics_Service.DAO
{
    public class BangGiaDAO
    {
        public BangGiaDTO[] GiaTheoKm(string sokm)
        {
            BangGiaDTO[] arr;
            int sk = int.Parse(sokm);
            string query = string.Format("select * from BangGia where SoKilomet > {0}",sk);
            DataProvider dp = new DataProvider();
            DataTable dt = dp.ExecuteQuery(query);
            int i, n = dt.Rows.Count;
            arr = new BangGiaDTO[n];
            for (i = 0; i < n; i++)
            {
                object bg = GetDataFromDataRow(dt, i);
                arr[i] = (BangGiaDTO)bg;
            }
            return arr;
        }
        protected object GetDataFromDataRow(DataTable dt, int i)
        {
            BangGiaDTO bgia = new BangGiaDTO();
            bgia.Ma = int.Parse(dt.Rows[i]["Ma"].ToString());
            bgia.SoKiLoMet = int.Parse(dt.Rows[i]["SoKilomet"].ToString());
            bgia.GiaMotKg=float.Parse(dt.Rows[i]["GiaMotKg"].ToString());
            bgia.DaXoa = bool.Parse(dt.Rows[i]["DaXoa"].ToString());

            return (object)bgia;
        }
    }
}